//
//  UnlockingHistoryTableViewCell.m
//  RONGAO
//
//  Created by Kendama on 2018/2/27.
//  Copyright © 2018年 wei wang. All rights reserved.
//

#import "UnlockingHistoryTableViewCell.h"
#import "UnlockingModel.h"
#import "AlertModel.h"

NSString *const kUnlockingHistoryTableViewCellIdentifier = @"kUnlockingHistoryTableViewCellIdentifier";

@implementation UnlockingHistoryTableViewCell

- (void)updateCellDataWithAlertModel:(AlertModel *)model
{
    if ([model isKindOfClass:[AlertModel class]]) {
        _timeLabel.text = model.alert_time;
        _contentLabel.text = model.desc;
    }
}

- (void)updateCellDataWithUnlockingModel:(UnlockingModel *)model
{
    if ([model isKindOfClass:[UnlockingModel class]]) {
        _timeLabel.text = model.open_time;
        _contentLabel.text = model.desc;
    }
}

+ (instancetype)dequeueReusableWithTableView:(UITableView *)tableView
{
    UnlockingHistoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUnlockingHistoryTableViewCellIdentifier];
    if (cell == nil)
    {
        cell = [[UnlockingHistoryTableViewCell alloc]init];
    }
    return cell;
}

- (instancetype)init
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUnlockingHistoryTableViewCellIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self masLayoutSubview];
    }
    return self;
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self.contentView;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
    }
    return _iconImageView;
}
- (UILabel *)timeLabel
{
    if(!_timeLabel)
    {
        UIView *superView = self.contentView;
        _timeLabel = [[UILabel alloc]init];
        [superView addSubview:_timeLabel];
        [_timeLabel setFont:[UIFont systemFontOfSize:13]];
        [_timeLabel setTextColor:[UIColor lightGrayColor]];
    }
    return _timeLabel;
}
- (UILabel *)contentLabel
{
    if(!_contentLabel)
    {
        UIView *superView = self.contentView;
        _contentLabel = [[UILabel alloc]init];
        [superView addSubview:_contentLabel];
        [_contentLabel setFont:[UIFont systemFontOfSize:14]];
        [_contentLabel setTextColor:[UIColor darkGrayColor]];
    }
    return _contentLabel;
}


- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(superView);
        make.left.mas_equalTo(superView.mas_left).with.offset(pxScaleWidth(50));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top);
        make.left.mas_equalTo(_iconImageView.mas_right).with.offset(pxScaleWidth(50));
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_timeLabel.mas_bottom).with.offset(pxScaleWidth(20));
        make.left.mas_equalTo(_timeLabel.mas_left);
    }];
    
}

@end
